/* 
 * Copyright (c) 2006 - 2014 QIU ZHONG HUAI <huai2011@163.com>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:

 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *    "This product includes CC software, freely available from
 *    <https://github.com/huai2001/CC/>".
 * 4. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.

 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef _C_CC_TYPES_H_INCLUDED_
#define _C_CC_TYPES_H_INCLUDED_

#define HAVE_ASSERT_H

#include <stddef.h>
#include <ctype.h>
#include <wctype.h>
#include "config_compiler.h"
/**
 *  name Cast operators
 *
 *  Use proper C++ casts when compiled as C++ to be compatible with the option
 *  -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
 */
/*@{*/
#ifdef __cplusplus
    #define cc_reinterpret_cast(type, expression) reinterpret_cast<type>(expression)
    #define cc_static_cast(type, expression) static_cast<type>(expression)
    #define cc_const_cast(type, expression) const_cast<type>(expression)
#else
    #define cc_reinterpret_cast(type, expression) ((type)(expression))
    #define cc_static_cast(type, expression) ((type)(expression))
    #define cc_const_cast(type, expression) ((type)(expression))
#endif
/*@}*//*Cast operators*/

/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif

/* Define NULL pointer value */
#ifndef NULL
    #ifdef __cplusplus
        #define NULL    0
    #else
        #define NULL    ((void *)0)
    #endif
#endif

/**
 *  name Basic data types
 */
/*@{*/
#ifndef TRUE
#define TRUE  1
#endif

#ifndef FALSE
#define FALSE  0
#endif

typedef char char_t;
typedef unsigned char uchar_t;
typedef uchar_t byte_t;
typedef char_t bool_t;

#if defined(_WINDOWS)
    #if defined(__MINGW32__)
        #include <sys/types.h>
        typedef char_t int8_t;
        typedef uchar_t uint8_t;
        typedef short int16_t;
        typedef unsigned short uint16_t;
        typedef int int32_t;
        typedef unsigned int uint32_t;
        typedef long long int int64_t;
        typedef unsigned long long int uint64_t;
    #elif defined(__MWERKS__)
        typedef char_t int8_t;
        typedef uchar_t uint8_t;
        typedef short int16_t;
        typedef unsigned short uint16_t;
        typedef int int32_t;
        typedef unsigned int uint32_t;
        typedef long long int int64_t;
        typedef unsigned long long uint64_t;
    #else
        /* MSVC/Borland */
        #ifdef _STDINT
        #else
        typedef __int8 int8_t;
        #endif
        typedef unsigned __int8 uint8_t;
        typedef __int16 int16_t;
        typedef unsigned __int16 uint16_t;
        typedef __int32 int32_t;
        typedef unsigned __int32 uint32_t;
        typedef __int64 int64_t;
        typedef unsigned __int64 uint64_t;
    #endif
#elif defined(CC_MACOS)
    #include <sys/types.h>
    typedef SInt8 int8_t;
    typedef UInt8 uint8_t;
    typedef SInt16 int16_t;
    typedef UInt16 uint16_t;
    typedef SInt32 int32_t;
    typedef UInt32 uint32_t;
    typedef SInt64 int64_t;
/* MacOS X Framework build */
#elif defined(CC_MACOSX) || defined(CC_IPHONEOS) || defined(CC_MACOS) || defined(CC_GCC)
    #include <inttypes.h>
    #include <sys/types.h>
    /*
    typedef int8_t int8_t;
    typedef uint8_t uint8_t;
    typedef int16_t int16_t;
    typedef uint16_t uint16_t;
    typedef int32_t int32_t;
    typedef uint32_t uint32_t;
    typedef int64_t int64_t;
    */
#elif defined(CC_CYGWIN)
        #include <stdint.h>
        /*
        typedef char int8_t;
        typedef unsigned char uint8_t;
        typedef short int16_t;
        typedef unsigned short uint16_t;
        typedef int int32_t;
        typedef unsigned int uint32_t;
        typedef long long int64_t;
        typedef unsigned long long uint64_t;
        */
#elif defined(CC_ANDROID)
    #include <stdlib.h>
    //#include <inttypes.h>      /* C99 */
#else
    typedef char_t int8_t;
    typedef uchar_t uint8_t;
    typedef short int16_t;
    typedef unsigned short uint16_t;
    typedef int int32_t;
    typedef unsigned int uint32_t;
    typedef long long int64_t;
    typedef unsigned long long int uint64_t;
#endif

/**/
typedef int8_t      cc_int8_t;
typedef int16_t     cc_int16_t;
typedef int32_t     cc_int32_t;
typedef int64_t     cc_int64_t;
typedef uint8_t     cc_uint8_t;
typedef uint16_t    cc_uint16_t;
typedef uint32_t    cc_uint32_t;
typedef uint64_t    cc_uint64_t;
typedef byte_t      cc_byte_t;
typedef long		cc_long_t;
typedef unsigned long cc_ulong_t;

/**/
#ifndef __cplusplus
    #if (!defined (PRO_WCHAR_T_H) && !defined (_WCHAR_T))
        #define _WCHAR_T
        #ifdef __darwin_wchar_t
            typedef __darwin_wchar_t wchar_t
        #else
            typedef unsigned short wchar_t; /*  Use a 2 byte definition  */
        #endif
    #endif
#endif

/**/
#ifndef _UNICODE
    typedef char_t tchar_t;
#else
    typedef wchar_t tchar_t;
#endif

/**/
typedef uint16_t us2char_t;
typedef uint32_t us4char_t;

/**/
#ifdef _WINDOWS
    #ifndef word_t
        typedef uint16_t word_t;
    #endif
    #ifndef dword_t
        typedef unsigned long dword_t;
    #endif
#else
    #ifndef word_t
        typedef uint16_t word_t;
    #endif
    #ifndef dword_t
        typedef uint32_t dword_t;
    #endif
#endif

#ifndef pvoid_t
    typedef void *pvoid_t;
    typedef void *lpvoid_t;
#endif

/**/
#ifndef _W64
#define _W64
#endif

/**/
#ifdef CC_CPU_X64
	typedef int64_t         cc_int_t;
	typedef uint64_t        cc_uint_t;
#elif defined(CC_CPU_X86)
    typedef _W64 int32_t    cc_int_t;
    typedef _W64 uint32_t   cc_uint_t;
#else
    typedef _W64 int32_t    cc_int_t;
    typedef _W64 uint32_t   cc_uint_t;
#endif

/**/
typedef uint32_t cc_result_t;
#define CC_RESULT_SUCCESS    0

/*@}*//*Basic data types*/

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}    /* ... extern "C" */
#endif

#endif /* _C_CC_TYPES_H_INCLUDED_ */
